import { SET_USER, CLEAR_USER } from "../actionType"
import { IState, IAction } from "../../interface"

const initState: IState = {
    user: {
        id: 1,
        content: '',
        username: "",
        msg_state: false,
        role: "",
        token: "",
        author_img: '',
    }
}


export const userReducer = (state = initState, action: IAction) => {
    const { type, payload = 1 } = action
    switch (type) {
        case SET_USER:
            return { ...state, user: payload }
            break;
        case CLEAR_USER:
            return {
                ...state, user: {
                    id: 1,
                    content: '',
                    username: "",
                    msg_state: false,
                    role: "",
                    token: "",
                    author_img: '',
                }
            }
            break;
        default:
            return state
    }
}
